package com.liveHere.www.util;

import java.sql.*;

/**
 * @author Mo312
 */
public class JDBCUtils {
    public static final String URL = "jdbc:mysql://10.44.166.223:3306/livehere?useSSL=false";
    public static final String USER = "TestUser";
    public static final String PASSWORD = "Mo20060812";

    //加载驱动
    static {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    //链接
    public static Connection getConnection() throws SQLException {
        return DriverManager.getConnection(URL, USER, PASSWORD);
    }

    //关闭
    public static void close(Connection conn, PreparedStatement pstmt, ResultSet rs) {
        try {
            if (rs != null) {
                rs.close();
            }
            if (pstmt != null) {
                pstmt.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
